package com.cy.sys.web.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.common.util.PageUtil;
import com.cy.sys.pojo.SysRole;
import com.cy.sys.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role/")
public class SysRoleController {
    @Autowired
    private SysRoleService service;

    @GetMapping("{id}")
    public JsonResult doFindById(@PathVariable Integer id){
        return new JsonResult(service.findById(id));
    }

    @PutMapping
    public JsonResult doupdateRole(@RequestBody SysRole sysRole){
        service.updateRole(sysRole);
        return  new JsonResult("update Ok");
    }
    @PostMapping
    public JsonResult doSaveRole(@RequestBody SysRole sysRole){
        service.saveRole(sysRole);
        return new JsonResult("save ok");
    }

    @GetMapping
    public JsonResult doFindRoles(SysRole sysRole) {//pageCurrent(当前页码),pageSize
//      //获取当前页面大小(页面显示的条数)
//       String pageSizeStr = request.getParameter("pageSize");
//       //获取当前页码值
//       String pageCurrentStr = request.getParameter("pageCurrent");
//       Integer pageCurrent = pageSizeStr == null || "".equals(pageCurrentStr)?1:Integer.parseInt(pageCurrentStr);
//       Integer pageSize = pageSizeStr == null || "".equals(pageSizeStr)?5:Integer.parseInt(pageSizeStr);
////       启动分页查询
//       PageInfo<PageInfo>pageInfo =  PageHelper.startPage(pageCurrent,pageSize).doSelectPageInfo(()->{
//            service.findRoles(sysRole);
//        });
//       return new JsonResult(pageInfo);

        return new JsonResult(PageUtil.startPage().doSelectPageInfo(() -> {
            service.findRoles(sysRole);
        }));

//        return new JsonResult(()->service.findRoles(sysRole));
    }
}
